<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<form action="<?php echo url_for('invoices/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id_invoice='.$form->getObject()->getIdInvoice() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>
<?php echo $form->renderGlobalErrors() ?>

<h1>Billing Address</h1>
<span class="nombre-campo">
        <?php echo $form['billing_name']->renderLabel() ?>
          <?php echo $form['billing_name']->renderError() ?>
          <?php echo $form['billing_name'] ?>
  </span><br />
        <span class="nombre-campo">
        <?php echo $form['billing_last_name']->renderLabel() ?>
          <?php echo $form['billing_last_name']->renderError() ?>
          <?php echo $form['billing_last_name'] ?>
      </span><br />
 <span class="nombre-campo"> <?php echo $form['billing_company']->renderLabel() ?>
          <?php echo $form['billing_company']->renderError() ?>
          <?php echo $form['billing_company'] ?>
  </span><br />
       <span class="nombre-campo"><?php echo $form['billing_address']->renderLabel() ?>
          <?php echo $form['billing_address']->renderError() ?>
          <?php echo $form['billing_address'] ?>
  </span><br />
<span class="nombre-campo"><?php echo $form['billing_city']->renderLabel() ?>
          <?php echo $form['billing_city']->renderError() ?>
          <?php echo $form['billing_city'] ?>
  </span><br />
      <span class="nombre-campo">
      	<?php echo $form['billing_state']->renderLabel() ?>
          <?php echo $form['billing_state']->renderError() ?>
          <?php echo $form['billing_state'] ?>
       
      </span><br />
       <span class="nombre-campo">
      <?php echo $form['billing_zip']->renderLabel() ?>
        
          <?php echo $form['billing_zip']->renderError() ?>
          <?php echo $form['billing_zip'] ?>
     
       </span><br />
		 <span class="nombre-campo"><?php echo $form['billing_phone']->renderLabel() ?>
          <?php echo $form['billing_phone']->renderError() ?>
          <?php echo $form['billing_phone'] ?>
      </span><br />
      <span class="nombre-campo">
      <?php echo $form['billing_fax']->renderLabel() ?>
        
          <?php echo $form['billing_fax']->renderError() ?>
          <?php echo $form['billing_fax'] ?>
       
      </span><br />
      <span class="nombre-campo">
 <?php echo $form['billing_email']->renderLabel() ?>
          <?php echo $form['billing_email']->renderError() ?>
          <?php echo $form['billing_email'] ?>
  
      </span><br />
      <p>Use Billing Address as Shipping Address <input type="checkbox" name="check" onclick="return autoFillShipping(this.form)"/></p>
      <br />
      <h1>Shipping Address</h1>
      <br />
 <span class="nombre-campo">
<?php echo $form['shipping_name']->renderLabel() ?>
          <?php echo $form['shipping_name']->renderError() ?>
          <?php echo $form['shipping_name'] ?>
  </span><br />
<span class="nombre-campo"><?php echo $form['shipping_last_name']->renderLabel() ?>
          <?php echo $form['shipping_last_name']->renderError() ?>
          <?php echo $form['shipping_last_name'] ?>
    
  </span><br />
      <span class="nombre-campo"><?php echo $form['shipping_company']->renderLabel() ?>
          <?php echo $form['shipping_company']->renderError() ?>
          <?php echo $form['shipping_company'] ?>
 </span><br />
 <span class="nombre-campo"> <?php echo $form['shipping_address']->renderLabel() ?>
          <?php echo $form['shipping_address']->renderError() ?>
          <?php echo $form['shipping_address'] ?></span><br />
          <span class="nombre-campo">
        <?php echo $form['shipping_city']->renderLabel() ?>
        
          <?php echo $form['shipping_city']->renderError() ?>
          <?php echo $form['shipping_city'] ?>
  </span><br />
            <span class="nombre-campo">
<?php echo $form['shipping_state']->renderLabel() ?>
          <?php echo $form['shipping_state']->renderError() ?>
          <?php echo $form['shipping_state'] ?>
  
            </span><br />
 <span class="nombre-campo">
 	  <?php echo $form['shipping_zip']->renderLabel() ?>
        
          <?php echo $form['shipping_zip']->renderError() ?>
          <?php echo $form['shipping_zip'] ?>
      
 </span><br />
    <input type="submit" value="Continue" onclick="return checkCheckout(this.form);" class="button-enter" />

  <table>
    <tfoot>
      <tr>
        <td colspan="2">
          <?php echo $form->renderHiddenFields(false) ?>
          &nbsp;
          <?php if (!$form->getObject()->isNew()): ?>
            &nbsp;<?php echo link_to('Delete', 'invoices/delete?id_invoice='.$form->getObject()->getIdInvoice(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
          <?php endif; ?>
            
        </td>
      </tr>
    </tfoot>
    <tbody>
      
      <tr>
        <th></th>
        <td>
          <?php echo $form['status']->renderError() ?>
          <input type="hidden" name="invoice[status]" id="invoice_status" value="1">
        </td>
      </tr>
      <tr>
        <th></th>
        <td>
          <?php echo $form['is_paid']->renderError() ?>
            <input type="hidden" name="invoice[is_paid]" id="invoice_is_paid" value="0">
        </td>
      </tr>
      <tr>
        <th></th>
        <td>
          <?php echo $form['invoice_amount']->renderError() ?>
            <?php echo $form['id_user']->renderError() ?>
            <input type="hidden" name="invoice[invoice_amount]" id="invoice_invoice_amount" value="<?php echo $amount ?>">
            <input type="hidden" name="invoice[id_user]" id="invoice_id_user" value="<?php echo $sf_user->getAttribute('id_user'); ?>">
        </td>
      </tr>
      <tr>
        <th></th>
        <td>
          <?php echo $form['shipping_amount']->renderError() ?>
          <input type="hidden" name="invoice[shipping_amount]" id="invoice_shipping_amount" value="<?php echo $shipping ?>">
        </td>
      </tr>
      <tr>
        <th></th>
        <td>
        </td>
      </tr>  
      <tr>
        <th></th>
        <td>
        </td>
      </tr>    
    <input type="hidden" name="checkout" value="2">
      <?php foreach($products as $array => $product_param) :
          $product = explode(',', $product_param);
          $product_quantity = $product[1];
          $product_id = $product[0] ;
		//Concatemacion de item
       ?>
         <input type="hidden" name="product[]" value="<?php echo implode(',',array('id_product' => $product_id, 'quantity' => $product_quantity)) ?>">
       <?php
       endforeach;
       ?>
    </tbody>
  </table>
</form>
